      *> File Name     000013_Arrays.cbl.
      *> Description   Using .NET arrays.
      *> Project Type  Console Application.
      *> CodePlex URL  http://cobol.codeplex.com
 
       program-id.   Main.
       repository.
           class sys-console as "System.Console"
           .
       working-storage section.
       01  a    object        occurs any.
       01  len  binary-long.
       procedure division.
           move "Using .NET Arrays" to sys-console::"Title"
           
           set content of a to (0, 4, 7, 3, 6)
           call "ShowValues" using " Unsorted array:", a
           
           invoke type "System.Array"::"Sort"(a)
           call "ShowValues" using "   Sorted array:", a
           
          *> .NET methods typically use 0-based indexes:
           move a::"Length" to len
           invoke a::"SetValue"(2, len - 1)
           
          *> COBOL array indexing syntax uses 1-based indexes:
           display string::"Format"(" New last value: {0}", a(len))
           call "ShowValues" using "  Changed array:", a
           
           display "Array type: " a::"GetType" "."
           display "Unboxed element type: " a(1)::"GetType" "."
           
           display "Press any key to continue . . . " no advancing
           invoke sys-console::"ReadKey"(true)
           .
       end program   Main.

       function-id.  ShowValues.
       local-storage section.
       01  o  object.
       linkage section.
       01  a  object  occurs any.
       01  s  string.
       procedure division using by reference s, a.
           if a::"Length" = 0 then
               display "The array is empty."
           else
               display s " " no advancing
               perform varying o through a
                   display string::"Format"("{0} ", o) no advancing
               end-perform
               display string::"Empty" *> terminate the line
           end-if
           .
       end function  ShowValues.